import dotenv from "dotenv";

dotenv.config();

const DEFAULT_PORT = 4000;

export const env = {
  nodeEnv: process.env.NODE_ENV ?? "development",
  port: (() => {
    const raw = process.env.PORT;
    const parsed = raw ? Number(raw) : DEFAULT_PORT;
    if (Number.isNaN(parsed) || parsed <= 0) {
      // 回退到默认端口，避免因配置错误导致服务无法启动
      return DEFAULT_PORT;
    }
    return parsed;
  })(),
};

export type Env = typeof env;








